package com.ahu.qifei.fund.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @author ShiQifei
 * @date 2020/11/21 16:03
 */
@Configuration
public class CommonConfig {
    @Value("${yunda.mail.username}")
    String userName;
    @Value("${yunda.mail.password}")
    String password;
    @Value("${yunda.mail.default-encoding}")
    String defaultEncoding;
    @Value("${yunda.mail.host}")
    String host;

    @Bean("yundasys")
    public JavaMailSender createSender() {
        JavaMailSenderImpl instance = new JavaMailSenderImpl();
        instance.setHost(host);
        instance.setDefaultEncoding(defaultEncoding);
        instance.setUsername(userName);
        instance.setPassword(password);

        Properties javaMailProperties = new Properties();
        javaMailProperties.setProperty("mail.smtp.ssl.enabled", "true");
        javaMailProperties.setProperty("mail.smtp.ssl.required", "true");
        instance.setJavaMailProperties(javaMailProperties);
        return instance;
    }
}
